<%@page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%><!DOCTYPE HTML>
TODO
<html>
<head>
<script src="${ctx}/static/admin/easyui/frame/window.js" type="text/javascript"></script>
<script src="${ctx}/static/admin/plugins/raphael-min.js" type="text/javascript"></script>
<script src="${ctx}/static/admin/plugins/bpmn.js" type="text/javascript"></script>
<script type="text/javascript">
	$(function() {
		$('#toolbar').toolbar({buttons:[
       		{name:'deploy',iconCls:'icon-add',text:'发布流程',disabled:true},
       		{name:'setVar',iconCls:'icon-edit',text:'设置任务变量',disabled:true},
       		{name:'assignPost',iconCls:'icon-users',text:'设置任务岗位',disabled:true}
       		
      	],handler:handler});
		$('#grid').datagrid({url: 'pagePd.do',title:'流程列表',pagination:true,singleSelect:true,rownumbers:true,striped:true,fit:true,fitColumns:true,
			columns:[[
	        	{field:'pdKey',title:'流程标识',width:160},
				{field:'pdName',title:'流程名称',width:300},
				{field:'pdVer',title:'流程版本',width:160}
			]]
			,onClickRow:function(i,r) {
				$('#toolbar').toolbar('enableAll'); //启动所有按钮
			}
			,onBeforeLoad:function(param) {
				$('#toolbar').toolbar('deploy');
			}
		});
		
		$('#btnsave').click(function() {
			$('form').submit();
		});
	});

	function handler() {
		if(this.name == 'search') return toSearch();
		if(this.name == 'deploy') return toDeploy();
		var item = $('#grid').datagrid('getSelected');
		if(!item) return;
		switch(this.name) {
		case 'pub': toPub(item);break;
		case 'setVar': toSetVar(item);break;
		case 'assignPost': toAssignPost(item);break;
		}
	}
	
	function toDeploy(){
		showUpload({title:'上传流程文件'
			,options:{
				filters:{
					mime_types: [{title : "流程定义", extensions : "bpmn"}]
				},
				complete:function(){
					var $this=this;
					var params=[];
					for(var i=0;i<$this.length;i++){
						console.log($this[i]);
						params[params.length]={name:'ids',value:$this[i].id};
					}
					$.post('deploy.do',params,function(r){
						if(r.code<0)return top.$alert(r.msg);
						top.$ok('流程发布成功');
					},'json');
				}
			}
		});
	}
	
	function toSetVar(item) {
		show({title : '设置任务变量', uri : 'editVar.do?id='+item.id, maximized:true,iconCls : 'icon-add', width : 600, height : 480,
			options : {
				obj : item,
				success : function(data) { $('#grid').datagrid('reload'); }
			}
		});
	}
	
	function toAssignPost(item){
		show({title : '设置任务岗位', uri : 'assignPost.do?id='+item.id, maximized:true,iconCls : 'icon-add', width : 600, height : 480,
			options : {
				obj : item,
				success : function(data) { $('#grid').datagrid('reload'); }
			}
		});
	}
	
	function saveVar(){
		
	}
	function doSave() {
		$.submit('#dataform',function(r) {
			if(r.code<0) return $alert(r.msg);
			$('#dialog').dialog('close');
			$('#grid').datagrid('reload');
			$prompt('保存成功');
		});
	}
	/*
	$("#canvas").bpmn({data:'pdBpmn.do?id='+encodeURIComponent('${pd.id}'),options:{
		onSelect:function(node,el) {
			if(node.type != 'task') return;
		}
	}});*/
</script>
</head>
<body>
	<div id="toolbar" class="toolbar"></div>
	<div class="easyui-layout" data-options="fit:true">
	    <div data-options="region:'center',border:false" style="padding-bottom: 33px">
			<table id="grid"></table>
	    </div>
    </div>
	<div id="dialogVar" class="easyui-dialog" data-options="title:'设置任务变量',iconCls:'icon-post',closed:true,modal:true,width:900,height:700,top:30,buttons:[{iconCls:'icon-save',text:'保存',handler:saveVar}]">
		<ul id="setVar">
			<div id="canvas"></div>
		</ul>
	</div>
</body>
</html>